home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / intuition / closewindow.c < prev    next >
C/C++ Source or Header  |  1996-11-08  |  4KB  |  160 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: closewindow.c,v 1.7 1996/11/08 11:28:00 aros Exp $
  4.     $Log: closewindow.c,v $
  5.     Revision 1.7  1996/11/08 11:28:00  aros
  6.     All OS function use now Amiga types
  7.  
  8.     Moved intuition-driver protos to intuition_intern.h
  9.  
  10.     Revision 1.6  1996/10/31 13:50:55  aros
  11.     Don't forget to free the RastPort
  12.  
  13.     Revision 1.5  1996/10/24 15:51:18  aros
  14.     Use the official AROS macros over the __AROS versions.
  15.  
  16.     Revision 1.4  1996/10/15 15:45:31  digulla
  17.     Two new functions: LockIBase() and UnlockIBase()
  18.     Modified code to make sure that it is impossible to access illegal data (ie.
  19.     fields of a window which is currently beeing closed).
  20.  
  21.     Revision 1.3  1996/09/21 14:16:26  digulla
  22.     Debug code
  23.     Only change the ActiveWindow is it is beeing closed
  24.     Search for a new ActiveWindow
  25.  
  26.     Revision 1.2  1996/08/29 13:33:30  digulla
  27.     Moved common code from driver to Intuition
  28.     More docs
  29.  
  30.     Revision 1.1  1996/08/13 15:37:26  digulla
  31.     First function for intuition.library
  32.  
  33.  
  34.     Desc:
  35.     Lang: english
  36. */
  37. #include "intuition_intern.h"
  38. #include <clib/exec_protos.h>
  39. #include <clib/graphics_protos.h>
  40.  
  41. #ifndef DEBUG_CloseWindow
  42. #   define DEBUG_CloseWindow 0
  43. #endif
  44. #if DEBUG_CloseWindow
  45. #   undef DEBUG
  46. #   define DEBUG 1
  47. #endif
  48. #include <aros/debug.h>
  49.  
  50. /*****************************************************************************
  51.  
  52.     NAME */
  53.     #include <clib/intuition_protos.h>
  54.  
  55.     AROS_LH1(void, CloseWindow,
  56.  
  57. /*  SYNOPSIS */
  58.     AROS_LHA(struct Window *, window, A0),
  59.  
  60. /*  LOCATION */
  61.     struct IntuitionBase *, IntuitionBase, 12, Intuition)
  62.  
  63. /*  FUNCTION
  64.     Closes a window. Depending on the display, this might not happen
  65.     at the time when this function returns, but you must not use
  66.     the window pointer after this function has been called.
  67.  
  68.     INPUTS
  69.     window - The window to close
  70.  
  71.     RESULT
  72.     None.
  73.  
  74.     NOTES
  75.     The window might not have been disappeared when this function returns.
  76.  
  77.     EXAMPLE
  78.  
  79.     BUGS
  80.  
  81.     SEE ALSO
  82.     OpenWindow(), OpenWindowTags()
  83.  
  84.     INTERNALS
  85.  
  86.     HISTORY
  87.     29-10-95    digulla automatically created from
  88.                 intuition_lib.fd and clib/intuition_protos.h
  89.  
  90. *****************************************************************************/
  91. {
  92.     AROS_LIBFUNC_INIT
  93.     AROS_LIBBASE_EXT_DECL(struct IntuitionBase *,IntuitionBase)
  94.     struct IntuiMessage * im;
  95.     ULONG lock;
  96.  
  97.     D(bug("CloseWindow (%p)\n", window));
  98.  
  99.     lock = LockIBase (0);
  100.  
  101.     if (window->MoreFlags & EWFLG_DELAYCLOSE)
  102.     {
  103.     window->MoreFlags |= EWFLG_CLOSEWINDOW;
  104.     ReturnVoid ("CloseWindow");
  105.     }
  106.  
  107.     if (window == IntuitionBase->ActiveWindow)
  108.     IntuitionBase->ActiveWindow = NULL;
  109.  
  110.     /* Remove window from the chain and find next active window */
  111.     if (window->Descendant)
  112.     {
  113.     window->Descendant->Parent = window->Parent;
  114.     ActivateWindow (window->Descendant);
  115.     }
  116.     if (window->Parent)
  117.     {
  118.     window->Parent->NextWindow =
  119.         window->Parent->Descendant =
  120.         window->Descendant;
  121.  
  122.     if (!IntuitionBase->ActiveWindow)
  123.         ActivateWindow (window->Parent);
  124.     }
  125.  
  126.     /* Make sure the Screen is still valid */
  127.     if (window == window->WScreen->FirstWindow)
  128.     window->WScreen->FirstWindow = window->NextWindow;
  129.  
  130.     UnlockIBase (lock);
  131.  
  132.     /* Let the driver clean up */
  133.     intui_CloseWindow (window, IntuitionBase);
  134.  
  135.     /* Free resources */
  136.     CloseFont (window->RPort->Font);
  137.  
  138.     FreeRastPort (window->RPort);
  139.  
  140.     if (window->UserPort)
  141.     {
  142.     /* Delete all pending messages */
  143.     Forbid ();
  144.  
  145.     while ((im = (struct IntuiMessage *) GetMsg (window->UserPort)))
  146.         ReplyMsg ((struct Message *)im);
  147.  
  148.     Permit ();
  149.  
  150.     /* Delete message port */
  151.     DeleteMsgPort (window->UserPort);
  152.     }
  153.  
  154.     /* Free memory for the window */
  155.     FreeMem (window, intui_GetWindowSize ());
  156.  
  157.     ReturnVoid ("CloseWindow");
  158.     AROS_LIBFUNC_EXIT
  159. } /* CloseWindow */
  160.